/*
 * Copyright (c) 2011 University of Tartu
 */
package org.qsardb.curation;

import org.qsardb.model.*;
import org.qsardb.visitor.*;

public class InChIGenerator extends Visitor {

	@Override
	public void visit(Qdb qdb) throws Exception {
		CompoundRegistry compounds = qdb.getCompoundRegistry();

		boolean changed = false;

		for(Compound compound : compounds){
			String name = compound.getName();
			String inChI = compound.getInChI();

			compound.setInChI(MarvinUtil.nameToInChI(name));

			changed |= MarvinUtil.isChanged(inChI, compound.getInChI());
		}

		if(changed){
			compounds.storeChanges();
		}
	}
}